<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ga</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>ga</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jgenson/Development/betelgeuse-ml/lib/ml/ga.py">/home/jgenson/Development/betelgeuse-ml/lib/ml/ga.py</a></font></td></tr></table>
    <p><tt>A&nbsp;general&nbsp;implementation&nbsp;of&nbsp;genetic&nbsp;algorithm&nbsp;(GA).<br>
&nbsp;<br>
GA&nbsp;works&nbsp;by&nbsp;applying&nbsp;three&nbsp;evolutionary&nbsp;operators,&nbsp;mutation,&nbsp;selection,&nbsp;and<br>
crossover,&nbsp;to&nbsp;a&nbsp;randomly-generated&nbsp;"population",&nbsp;or&nbsp;list&nbsp;of&nbsp;"chromosomes"<br>
(potential&nbsp;solutions&nbsp;represented&nbsp;by&nbsp;a&nbsp;NumPy&nbsp;array&nbsp;of&nbsp;integers&nbsp;or&nbsp;floats),<br>
until&nbsp;the&nbsp;minimum&nbsp;solution&nbsp;"fitness"&nbsp;has&nbsp;been&nbsp;reached,&nbsp;or&nbsp;the&nbsp;maximum<br>
number&nbsp;of&nbsp;generations&nbsp;has&nbsp;been&nbsp;exceeded.<br>
In&nbsp;addition,&nbsp;an&nbsp;optional&nbsp;adaptation&nbsp;operator&nbsp;is&nbsp;defined&nbsp;that&nbsp;can&nbsp;be&nbsp;used&nbsp;to<br>
dynamically&nbsp;adapt&nbsp;the&nbsp;magnitude&nbsp;of&nbsp;mutations&nbsp;and&nbsp;the&nbsp;population&nbsp;size&nbsp;to<br>
improve&nbsp;the&nbsp;efficacy&nbsp;and&nbsp;performance&nbsp;of&nbsp;the&nbsp;algorithm.<br>
&nbsp;<br>
Most&nbsp;functions&nbsp;in&nbsp;this&nbsp;module&nbsp;are&nbsp;higher-order&nbsp;functions&nbsp;that&nbsp;return&nbsp;another<br>
function.&nbsp;To&nbsp;create&nbsp;a&nbsp;GA&nbsp;optimizer,&nbsp;you&nbsp;must&nbsp;minimally&nbsp;call&nbsp;create_optimizer<br>
with&nbsp;fitness,&nbsp;mutate,&nbsp;and&nbsp;crossover&nbsp;functions.&nbsp;The&nbsp;mutate&nbsp;and&nbsp;crossover<br>
functions&nbsp;are&nbsp;typically&nbsp;created&nbsp;with&nbsp;functions&nbsp;defined&nbsp;by&nbsp;this&nbsp;module<br>
(e.g.&nbsp;create_generic_mutate,&nbsp;create_point_crossover),&nbsp;though&nbsp;you&nbsp;may&nbsp;optionally<br>
define&nbsp;your&nbsp;own.&nbsp;You&nbsp;must&nbsp;supply&nbsp;the&nbsp;fitness&nbsp;function&nbsp;yourself.<br>
&nbsp;<br>
Copyright&nbsp;(C)&nbsp;2013&nbsp;Jerrad&nbsp;Michael&nbsp;Genson<br>
&nbsp;<br>
This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;BSD&nbsp;3-Clause&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
the&nbsp;Open&nbsp;Source&nbsp;Initiative.<br>
&nbsp;<br>
This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
BSD&nbsp;3-Clause&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
&nbsp;<br>
You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;BSD&nbsp;3-Clause&nbsp;License<br>
along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see<br>
&lt;https://betelgeuse-ml.googlecode.com/hg/LICENSE&gt;</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="copy.html">copy</a><br>
<a href="math.html">math</a><br>
</td><td width="25%" valign=top><a href="numpy.html">numpy</a><br>
<a href="optimize.html">optimize</a><br>
</td><td width="25%" valign=top><a href="random.html">random</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ga.html#ChromosomeGroup">ChromosomeGroup</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="ChromosomeGroup">class <strong>ChromosomeGroup</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Used&nbsp;to&nbsp;group&nbsp;duplicate&nbsp;chromosomes.&nbsp;Has&nbsp;attributes&nbsp;for&nbsp;the&nbsp;chromosome<br>
value&nbsp;itself,&nbsp;the&nbsp;fitness&nbsp;of&nbsp;the&nbsp;chromosome,&nbsp;and&nbsp;the&nbsp;number&nbsp;of&nbsp;times&nbsp;it<br>
is&nbsp;duplicated.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;chromosome&nbsp;The&nbsp;actual&nbsp;chromosome&nbsp;(usually&nbsp;a&nbsp;Numpy&nbsp;array).<br>
&nbsp;&nbsp;&nbsp;&nbsp;fitness:&nbsp;The&nbsp;fitness&nbsp;of&nbsp;the&nbsp;chromosome.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="ChromosomeGroup-__init__"><strong>__init__</strong></a>(self, chromosome, fitness)</dt></dl>

<dl><dt><a name="ChromosomeGroup-decrement"><strong>decrement</strong></a>(self)</dt><dd><tt>Decrement&nbsp;the&nbsp;<a href="#ChromosomeGroup">ChromosomeGroup</a>&nbsp;count&nbsp;by&nbsp;1.</tt></dd></dl>

<dl><dt><a name="ChromosomeGroup-increment"><strong>increment</strong></a>(self)</dt><dd><tt>Increment&nbsp;the&nbsp;<a href="#ChromosomeGroup">ChromosomeGroup</a>&nbsp;count&nbsp;by&nbsp;1.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>chromosome</strong></dt>
<dd><tt>The&nbsp;actual&nbsp;chromosome&nbsp;(usually&nbsp;a&nbsp;Numpy&nbsp;array).</tt></dd>
</dl>
<dl><dt><strong>count</strong></dt>
<dd><tt>The&nbsp;number&nbsp;of&nbsp;times&nbsp;the&nbsp;chromosome&nbsp;is&nbsp;duplicated.</tt></dd>
</dl>
<dl><dt><strong>fitness</strong></dt>
<dd><tt>The&nbsp;fitness&nbsp;of&nbsp;the&nbsp;chromosome.</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-create_adaptor"><strong>create_adaptor</strong></a>(fitness, max_mutation_rate<font color="#909090">=0.9</font>, min_mutation_rate<font color="#909090">=0.1</font>, max_population_decrease<font color="#909090">=0.2</font>, min_population_size<font color="#909090">=25</font>, mutation_adaptation<font color="#909090">=True</font>, population_adaptation<font color="#909090">=True</font>, adaptation_rate<font color="#909090">=10</font>)</dt><dd><tt>Create&nbsp;an&nbsp;adaptor&nbsp;function&nbsp;for&nbsp;use&nbsp;with&nbsp;genetic&nbsp;algorithm.<br>
The&nbsp;adaptation&nbsp;algorithm&nbsp;is&nbsp;a&nbsp;novel&nbsp;solution&nbsp;to&nbsp;the&nbsp;problem&nbsp;of&nbsp;choosing<br>
good&nbsp;population&nbsp;sizes&nbsp;and&nbsp;mutation&nbsp;magnitudes.&nbsp;It&nbsp;varies&nbsp;both&nbsp;values<br>
dynamically&nbsp;as&nbsp;GA&nbsp;runs,&nbsp;making&nbsp;adjustments&nbsp;to&nbsp;maximize&nbsp;solution&nbsp;quality.<br>
The&nbsp;idea&nbsp;is&nbsp;to&nbsp;start&nbsp;with&nbsp;an&nbsp;"exploration&nbsp;phase",&nbsp;with&nbsp;a&nbsp;large&nbsp;mutation<br>
rate&nbsp;and&nbsp;population&nbsp;size,&nbsp;and&nbsp;decrease&nbsp;both&nbsp;as&nbsp;the&nbsp;fitness&nbsp;increases&nbsp;to<br>
transition&nbsp;to&nbsp;an&nbsp;"exploitation&nbsp;phase"&nbsp;that&nbsp;converges&nbsp;quickly.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;fitness:&nbsp;A&nbsp;function&nbsp;that&nbsp;accepts&nbsp;a&nbsp;chromosome&nbsp;as&nbsp;input&nbsp;and&nbsp;returns<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;its&nbsp;fitness&nbsp;as&nbsp;a&nbsp;real&nbsp;number&nbsp;between&nbsp;0&nbsp;and&nbsp;1.<br>
&nbsp;<br>
Keywords:<br>
&nbsp;&nbsp;&nbsp;&nbsp;max_mutation_rate:&nbsp;The&nbsp;maximum&nbsp;mutation&nbsp;magnitude&nbsp;that&nbsp;adaptation<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;might&nbsp;choose.<br>
&nbsp;&nbsp;&nbsp;&nbsp;min_mutation_rate:&nbsp;The&nbsp;minimum&nbsp;mutation&nbsp;magnitude&nbsp;that&nbsp;adaptation<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;might&nbsp;choose.<br>
&nbsp;&nbsp;&nbsp;&nbsp;max_population_decrease:&nbsp;The&nbsp;maximum&nbsp;percentage&nbsp;that&nbsp;adaptation&nbsp;can<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reduce&nbsp;the&nbsp;population&nbsp;by.<br>
&nbsp;&nbsp;&nbsp;&nbsp;min_population_size:&nbsp;The&nbsp;minimum&nbsp;population&nbsp;size&nbsp;that&nbsp;adaptation&nbsp;can<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;choose.<br>
&nbsp;&nbsp;&nbsp;&nbsp;mutation_adaptation:&nbsp;True&nbsp;to&nbsp;adapt&nbsp;mutation&nbsp;size,&nbsp;or&nbsp;False&nbsp;to&nbsp;not.<br>
&nbsp;&nbsp;&nbsp;&nbsp;population_adaptation:&nbsp;True&nbsp;to&nbsp;adapt&nbsp;population&nbsp;size,&nbsp;or&nbsp;False&nbsp;to&nbsp;not.<br>
&nbsp;&nbsp;&nbsp;&nbsp;adaptation_rate:&nbsp;Specifies&nbsp;how&nbsp;many&nbsp;cycles&nbsp;of&nbsp;GA&nbsp;to&nbsp;complete<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;before&nbsp;running&nbsp;the&nbsp;adaptation&nbsp;algorithms.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;synthesized&nbsp;adapt&nbsp;function&nbsp;-&nbsp;see&nbsp;documentation&nbsp;for&nbsp;adapt.</tt></dd></dl>
 <dl><dt><a name="-create_generic_mutate"><strong>create_generic_mutate</strong></a>(bounds<font color="#909090">=None</font>)</dt><dd><tt>Create&nbsp;a&nbsp;generic&nbsp;mutation&nbsp;function.<br>
Makes&nbsp;a&nbsp;change&nbsp;to&nbsp;a&nbsp;number&nbsp;of&nbsp;genes&nbsp;(determined&nbsp;by&nbsp;magnitude)&nbsp;in&nbsp;the<br>
chromosome.&nbsp;The&nbsp;maximum&nbsp;amount&nbsp;of&nbsp;change&nbsp;that&nbsp;may&nbsp;be&nbsp;applied&nbsp;to&nbsp;a<br>
gene&nbsp;is&nbsp;also&nbsp;determined&nbsp;by&nbsp;the&nbsp;mutation&nbsp;rate.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;bounds:&nbsp;A&nbsp;range&nbsp;of&nbsp;values&nbsp;that&nbsp;genes&nbsp;can&nbsp;take&nbsp;on.&nbsp;Specified&nbsp;as&nbsp;a<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tuple&nbsp;of&nbsp;(low&nbsp;bound,&nbsp;high&nbsp;bound).<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;generic_mutate&nbsp;function.&nbsp;See&nbsp;documentation&nbsp;for&nbsp;generic_mutate.</tt></dd></dl>
 <dl><dt><a name="-create_null_crossover"><strong>create_null_crossover</strong></a>()</dt><dd><tt>Create&nbsp;a&nbsp;null&nbsp;crossover&nbsp;function.<br>
A&nbsp;crossover&nbsp;function&nbsp;that&nbsp;does&nbsp;nothing&nbsp;but&nbsp;return&nbsp;an&nbsp;unaltered&nbsp;chromosome.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;null_crossover&nbsp;function.&nbsp;See&nbsp;documentation&nbsp;for&nbsp;null_crossover.</tt></dd></dl>
 <dl><dt><a name="-create_null_mutate"><strong>create_null_mutate</strong></a>()</dt><dd><tt>Create&nbsp;a&nbsp;null&nbsp;mutation&nbsp;function.<br>
A&nbsp;mutation&nbsp;function&nbsp;that&nbsp;does&nbsp;nothing&nbsp;but&nbsp;return&nbsp;the&nbsp;unaltered<br>
chromosome&nbsp;that&nbsp;was&nbsp;given&nbsp;as&nbsp;input.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;null_mutate&nbsp;function.&nbsp;See&nbsp;documentation&nbsp;for&nbsp;null_mutate&nbsp;for&nbsp;details.</tt></dd></dl>
 <dl><dt><a name="-create_optimizer"><strong>create_optimizer</strong></a>(fitness, mutate, crossover, select<font color="#909090">=&lt;function create_tournament_select.&lt;locals&gt;.tournament_select&gt;</font>, adapt<font color="#909090">=None</font>, mutation_rate<font color="#909090">=0.1</font>, elitism<font color="#909090">=False</font>, *args)</dt><dd><tt>Create&nbsp;a&nbsp;genetic&nbsp;algorithm&nbsp;optimizer&nbsp;function.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;fitness:&nbsp;GA&nbsp;fitness&nbsp;operator.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;function&nbsp;that&nbsp;takes&nbsp;a&nbsp;chromosome&nbsp;and&nbsp;returns&nbsp;its<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fitness&nbsp;as&nbsp;a&nbsp;real&nbsp;number&nbsp;between&nbsp;0&nbsp;and&nbsp;1.<br>
&nbsp;&nbsp;&nbsp;&nbsp;mutate:&nbsp;GA&nbsp;mutation&nbsp;operator.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;function&nbsp;that&nbsp;takes&nbsp;a&nbsp;chromosome&nbsp;and&nbsp;a&nbsp;mutation<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;magnitude&nbsp;(real&nbsp;number&nbsp;between&nbsp;0&nbsp;and&nbsp;1)&nbsp;and&nbsp;mutates&nbsp;the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chromosome&nbsp;by&nbsp;that&nbsp;magnitude,&nbsp;returning&nbsp;the&nbsp;mutated<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chromosome.<br>
&nbsp;&nbsp;&nbsp;&nbsp;crossover:&nbsp;GA&nbsp;crossover&nbsp;operator.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;function&nbsp;that&nbsp;takes&nbsp;two&nbsp;parent&nbsp;chromosomes&nbsp;and<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;returns&nbsp;a&nbsp;hybrid&nbsp;child&nbsp;chromosome.<br>
&nbsp;&nbsp;&nbsp;&nbsp;select:&nbsp;GA&nbsp;selection&nbsp;operator.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;function&nbsp;that&nbsp;takes&nbsp;as&nbsp;inputs&nbsp;a&nbsp;chromosome&nbsp;list,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;fitness&nbsp;function,&nbsp;and&nbsp;the&nbsp;number&nbsp;of&nbsp;chromosomes&nbsp;to&nbsp;keep<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and&nbsp;returns&nbsp;a&nbsp;reduced&nbsp;("select")&nbsp;list&nbsp;of&nbsp;chromosomes.<br>
&nbsp;<br>
Keywords:<br>
&nbsp;&nbsp;&nbsp;&nbsp;adapt:&nbsp;GA&nbsp;adaptation&nbsp;operator.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;function&nbsp;that&nbsp;take&nbsp;a&nbsp;chromosome&nbsp;list&nbsp;as&nbsp;input&nbsp;and<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;returns&nbsp;tuple&nbsp;of&nbsp;(new&nbsp;mutation&nbsp;size,&nbsp;new&nbsp;population&nbsp;size).<br>
&nbsp;&nbsp;&nbsp;&nbsp;mutation_rate:&nbsp;A&nbsp;static&nbsp;mutation&nbsp;magnitude&nbsp;to&nbsp;use&nbsp;if&nbsp;mutation<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adaptation&nbsp;is&nbsp;not&nbsp;used.&nbsp;Must&nbsp;be&nbsp;a&nbsp;real&nbsp;number<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;between&nbsp;0&nbsp;and&nbsp;1.<br>
&nbsp;&nbsp;&nbsp;&nbsp;elitism:&nbsp;Set&nbsp;to&nbsp;True&nbsp;to&nbsp;always&nbsp;preserve&nbsp;the&nbsp;fittest&nbsp;chromosome<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;verbatim&nbsp;through&nbsp;selection,&nbsp;crossover,&nbsp;and&nbsp;mutation.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This&nbsp;will&nbsp;have&nbsp;the&nbsp;side-effect&nbsp;of&nbsp;increasing&nbsp;population<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size&nbsp;by&nbsp;one.<br>
&nbsp;<br>
*args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;Any&nbsp;number&nbsp;of&nbsp;post-processing&nbsp;functions&nbsp;that&nbsp;take&nbsp;a&nbsp;list&nbsp;of<br>
&nbsp;&nbsp;&nbsp;&nbsp;chromosomes&nbsp;as&nbsp;input&nbsp;and&nbsp;return&nbsp;a&nbsp;list&nbsp;of&nbsp;chromosomes&nbsp;as&nbsp;output,<br>
&nbsp;&nbsp;&nbsp;&nbsp;and&nbsp;run&nbsp;at&nbsp;the&nbsp;end&nbsp;of&nbsp;every&nbsp;GA&nbsp;cycle.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;genetic&nbsp;algorithm&nbsp;optimizer&nbsp;function.&nbsp;See&nbsp;documentation&nbsp;for<br>
&nbsp;&nbsp;&nbsp;&nbsp;ga_optimizer.</tt></dd></dl>
 <dl><dt><a name="-create_point_crossover"><strong>create_point_crossover</strong></a>()</dt><dd><tt>Create&nbsp;a&nbsp;single-point&nbsp;crossover&nbsp;function.<br>
A&nbsp;single&nbsp;point&nbsp;crossover&nbsp;function.&nbsp;The&nbsp;genetic&nbsp;algorithm&nbsp;crossover<br>
operator&nbsp;is&nbsp;used&nbsp;to&nbsp;produce&nbsp;a&nbsp;child&nbsp;chromosome&nbsp;from&nbsp;the&nbsp;combination<br>
of&nbsp;two&nbsp;parent&nbsp;chromosomes.&nbsp;This&nbsp;implementation&nbsp;of&nbsp;crossover&nbsp;works&nbsp;by<br>
splicing&nbsp;the&nbsp;first&nbsp;half&nbsp;of&nbsp;the&nbsp;first&nbsp;parent&nbsp;chromosome&nbsp;with&nbsp;the&nbsp;second<br>
half&nbsp;of&nbsp;the&nbsp;second&nbsp;parent&nbsp;chromosome&nbsp;to&nbsp;form&nbsp;the&nbsp;hybrid&nbsp;child<br>
chromosome.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;point_crossover&nbsp;function.&nbsp;See&nbsp;documentation&nbsp;for&nbsp;point_crossover.</tt></dd></dl>
 <dl><dt><a name="-create_random_crossover"><strong>create_random_crossover</strong></a>()</dt><dd><tt>Create&nbsp;a&nbsp;random&nbsp;crossover&nbsp;function.<br>
A&nbsp;crossover&nbsp;algorithm&nbsp;that&nbsp;takes&nbsp;genes&nbsp;from&nbsp;parent&nbsp;chromosomes&nbsp;at&nbsp;random<br>
instead&nbsp;of&nbsp;in&nbsp;a&nbsp;predefined&nbsp;sequence.&nbsp;Genes&nbsp;in&nbsp;the&nbsp;child&nbsp;will&nbsp;retain&nbsp;the<br>
order&nbsp;of&nbsp;the&nbsp;genes&nbsp;in&nbsp;the&nbsp;parents,&nbsp;however,&nbsp;each&nbsp;gene&nbsp;will&nbsp;be&nbsp;chosen&nbsp;at<br>
random&nbsp;from&nbsp;one&nbsp;of&nbsp;the&nbsp;two&nbsp;corresponding&nbsp;parent&nbsp;genes.&nbsp;Parent<br>
chromosomes&nbsp;need&nbsp;not&nbsp;be&nbsp;the&nbsp;same&nbsp;length&nbsp;to&nbsp;use&nbsp;this&nbsp;function&nbsp;(if&nbsp;the<br>
lengths&nbsp;differ,&nbsp;the&nbsp;algorithm&nbsp;will&nbsp;decide&nbsp;at&nbsp;random&nbsp;whether&nbsp;to&nbsp;complete<br>
the&nbsp;child&nbsp;with&nbsp;genes&nbsp;from&nbsp;the&nbsp;longer&nbsp;chromosome&nbsp;or&nbsp;not).<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;random_crossover&nbsp;function.&nbsp;See&nbsp;documentation&nbsp;for&nbsp;random_crossover.</tt></dd></dl>
 <dl><dt><a name="-create_roulette_select"><strong>create_roulette_select</strong></a>()</dt><dd><tt>Create&nbsp;a&nbsp;selection&nbsp;function&nbsp;using&nbsp;the&nbsp;roulette-wheel&nbsp;selection&nbsp;algorithm.<br>
In&nbsp;roulette-wheel&nbsp;selection,&nbsp;each&nbsp;chromosome&nbsp;has&nbsp;an&nbsp;equal&nbsp;chance&nbsp;of<br>
being&nbsp;considered&nbsp;for&nbsp;selection.&nbsp;When&nbsp;a&nbsp;chromosome&nbsp;is&nbsp;considered,&nbsp;a<br>
random&nbsp;real&nbsp;number&nbsp;between&nbsp;0&nbsp;and&nbsp;1&nbsp;is&nbsp;generated,&nbsp;and&nbsp;the&nbsp;chromosome&nbsp;is<br>
selected&nbsp;if&nbsp;its&nbsp;fitness&nbsp;is&nbsp;higher&nbsp;than&nbsp;that&nbsp;number.&nbsp;This&nbsp;process&nbsp;is<br>
repeated&nbsp;until&nbsp;the&nbsp;target&nbsp;keep&nbsp;value&nbsp;has&nbsp;been&nbsp;reached.&nbsp;Once&nbsp;a&nbsp;chromosome<br>
is&nbsp;selected,&nbsp;it&nbsp;is&nbsp;removed&nbsp;from&nbsp;the&nbsp;initial&nbsp;population.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;selection&nbsp;function.</tt></dd></dl>
 <dl><dt><a name="-create_shuffle_mutate"><strong>create_shuffle_mutate</strong></a>()</dt><dd><tt>Create&nbsp;a&nbsp;a&nbsp;mutation&nbsp;function&nbsp;using&nbsp;the&nbsp;shuffle&nbsp;mutation&nbsp;algorithm.<br>
A&nbsp;mutation&nbsp;algorithm&nbsp;that&nbsp;shuffles&nbsp;genes&nbsp;in&nbsp;a&nbsp;chromosome&nbsp;instead&nbsp;of<br>
modifying&nbsp;them&nbsp;in&nbsp;place.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;shuffle_mutate&nbsp;function.&nbsp;See&nbsp;documentation&nbsp;for&nbsp;shuffle_mutate.</tt></dd></dl>
 <dl><dt><a name="-create_tournament_select"><strong>create_tournament_select</strong></a>()</dt><dd><tt>Create&nbsp;a&nbsp;selection&nbsp;operator&nbsp;function&nbsp;using&nbsp;the&nbsp;tournament&nbsp;selection&nbsp;algorithm.<br>
Tournament&nbsp;selection&nbsp;works&nbsp;by&nbsp;choosing&nbsp;a&nbsp;few&nbsp;chromosomes&nbsp;from&nbsp;the&nbsp;population<br>
at&nbsp;random&nbsp;and&nbsp;having&nbsp;them&nbsp;"compete"&nbsp;in&nbsp;a&nbsp;tournament.&nbsp;The&nbsp;chromosome&nbsp;with&nbsp;the<br>
greatest&nbsp;fitness&nbsp;wins.&nbsp;This&nbsp;process&nbsp;is&nbsp;repeated&nbsp;until&nbsp;the&nbsp;target&nbsp;keep&nbsp;value<br>
has&nbsp;been&nbsp;reached.&nbsp;Chromosomes&nbsp;are&nbsp;discarded&nbsp;from&nbsp;the&nbsp;initial&nbsp;population&nbsp;upon<br>
selection.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;selection&nbsp;function.</tt></dd></dl>
 <dl><dt><a name="-create_truncate_select"><strong>create_truncate_select</strong></a>()</dt><dd><tt>Create&nbsp;a&nbsp;selection&nbsp;function&nbsp;using&nbsp;the&nbsp;truncation&nbsp;selection&nbsp;algorithm.<br>
In&nbsp;truncation&nbsp;selection,&nbsp;the&nbsp;fittest&nbsp;chromosomes&nbsp;are&nbsp;straightforwardly<br>
selected&nbsp;for&nbsp;survival.&nbsp;The&nbsp;keep&nbsp;value&nbsp;determines&nbsp;the&nbsp;number&nbsp;of&nbsp;chromosomes<br>
that&nbsp;are&nbsp;selected.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;selection&nbsp;function.</tt></dd></dl>
 <dl><dt><a name="-group_chromosomes"><strong>group_chromosomes</strong></a>(chromosomes, fitness)</dt><dd><tt>Organize&nbsp;chromosomes&nbsp;into&nbsp;groups&nbsp;as&nbsp;represented&nbsp;by&nbsp;the&nbsp;<a href="#ChromosomeGroup">ChromosomeGroup</a>&nbsp;class.<br>
A&nbsp;<a href="#ChromosomeGroup">ChromosomeGroup</a>&nbsp;contains&nbsp;the&nbsp;number&nbsp;of&nbsp;chromosomes&nbsp;in&nbsp;that&nbsp;group&nbsp;(i.e.&nbsp;the<br>
number&nbsp;of&nbsp;duplicates),&nbsp;the&nbsp;fitness&nbsp;for&nbsp;that&nbsp;chromosome,&nbsp;and&nbsp;the<br>
chromosome&nbsp;itself.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;chromosomes:&nbsp;A&nbsp;list&nbsp;of&nbsp;Numpy&nbsp;Arrays&nbsp;representing&nbsp;chromosomes.<br>
&nbsp;&nbsp;&nbsp;&nbsp;fitness:&nbsp;A&nbsp;fitness&nbsp;function&nbsp;that&nbsp;takes&nbsp;a&nbsp;chromosome&nbsp;and&nbsp;returns<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;its&nbsp;fitness&nbsp;as&nbsp;a&nbsp;real&nbsp;value&nbsp;between&nbsp;0&nbsp;and&nbsp;1.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;list&nbsp;of&nbsp;<a href="#ChromosomeGroup">ChromosomeGroup</a>&nbsp;instances.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>ADAPTATION_RATE</strong> = 10<br>
<strong>MAX_MUTATION_RATE</strong> = 0.9<br>
<strong>MAX_POPULATION_DECREASE</strong> = 0.2<br>
<strong>MIN_MUTATION_RATE</strong> = 0.1<br>
<strong>MIN_POPULATION_SIZE</strong> = 25<br>
<strong>__contact__</strong> = 'jerradgenson@gmail.com'<br>
<strong>__copyright__</strong> = 'Copyright 2013 Jerrad Michael Genson'<br>
<strong>__license__</strong> = 'BSD 3-Clause'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Jerrad&nbsp;Genson</td></tr></table>
</body></html>